<input type="hidden" id="manage_group_status" value="<?php echo $this->session->flashdata('manage_group_status'); ?>" />
<script type="text/javascript">
  $(document).ready(function() {
    $("#group_event_date").datepicker({
      format: 'dd-mm-yyyy'
    });
    var manage_group_status = $.trim($('#manage_group_status').val());
    if (manage_group_status == 1) {
      toastr.success('Group event results added successfully !');
      return false;
    } else if (manage_group_status == 2) {
      toastr.error('Error occured. Try again !');
      return false;
    } else if (manage_group_status == 3) {
      toastr.success('Group event deleted successfully !');
      return false;
    } else if (manage_group_status == 4) {
      toastr.success('Group event results updated successfully !');
      return false;
    }
  });
</script>
<div class="page" style="min-height: 500px;">
  <div class="page-container">
    <div class="container">
      <div class="row">
        <div class="span3">
          <h4 class="header">Manage Groups</h4>
          <div class="sidebar">
            <ul class="col-nav span3">
              <li><a href="<?php echo base_url('groups_manage/group/'); ?>"><i class="pull-right icon-th-large"></i>Manage Groups</a></li>
              <li><a href="<?php echo base_url('groups_manage/group_member/'); ?>"><i class="pull-right icon-user"></i>Manage Group Members</a></li>
              <li><a href="<?php echo base_url('groups_manage/group_event/'); ?>"><i class="pull-right icon-th-list"></i>Manage Group Events</a></li>
              <li><a style="background-color: #EEE;" href="<?php echo base_url('groups_manage/group_event_result/'); ?>"><i class="pull-right icon-signal"></i>Manage Group Event Results</a></li>
              <li><a href="<?php echo base_url('groups_manage/api_apps/'); ?>"><i class="pull-right icon-fire"></i>API Apps</a></li>
            </ul>
          </div>
        </div>
        <div class="span9">
          <div class="btn-group pull-right">
            <a title="<?php echo 'Can accessed by : @' . @implode(', @', $this->comitte_members); ?>" href="<?php echo base_url('groups_manage'); ?>" class="btn">Manage groups</a>
          </div>
          <h4 class="header">Group event results [<?php echo NOW_YEAR; ?>]</h4>
          <?php if (!empty($group_events)) { ?>
            <div class="control-group">
              <label class="control-label">Select group event</label>
              <div class="controls">
                <select onchange="location = this.options[this.selectedIndex].value;" style="width: 100%;">
                  <option value="0">--</option>
                  <?php foreach ($group_events as $group_event) { ?>
                    <option <?php if ($group_event_id == $group_event['group_event_id']) { ?> selected="selected" <?php } ?> value="<?php echo site_url('groups_manage/group_event_result') . '/' . $group_event['group_event_id']; ?>"><a><?php echo $group_event['group_event_name']; ?></option>
                    <?php } ?>
                </select>
              </div>
            </div>
            <?php if (!empty($group_event_data)) { ?>
              <?php if (!empty($groups)) { ?>
                <?php if (!empty($group_event_results)) { ?>
                  <label class="control-label">Update event results</label>
                  <div id="update_group_event_result">
                    <form class="form-horizontal" method="post" action="<?php echo base_url('groups_manage/group_event_result_update'); ?>">
                      <input type="hidden" name="csrf_token" value="<?php echo set_csrf_token(); ?>"/>
                      <input type="hidden" name="group_event_id" value="<?php echo $group_event_id; ?>"/>
                      <div>
                        <table class="table table-striped table-bordered">
                          <thead>
                            <tr>
                              <th width="5%">#</th>
                              <th width="50%">Group name</th>
                              <th width="10%">Score</th>
                              <th width="35%">Info</th>
                            </tr>
                          </thead>
                          <tbody>
                            <?php $count = 1; ?>
                            <?php foreach ($group_event_results as $result) { ?>
                              <tr>
                                <td><?php echo $count; ?></td>
                                <td><?php echo $result['group_name']; ?></td>
                                <td><input name="group_score_<?php echo $result['group_id']; ?>" type="number" min="0" max="<?php echo (int) $group_event_data['group_event_max_score']; ?>" step="1" pattern="\d+" value="<?php echo $result['group_event_result_score']; ?>" placeholder="0 - <?php echo (int) $group_event_data['group_event_max_score']; ?>"/></td>
                                <td><input name="group_info_<?php echo $result['group_id']; ?>" type="text" value="<?php echo $result['group_event_result_info']; ?>"/></td>
                              </tr>
                              <?php $count++; ?>
                            <?php } ?>
                          </tbody>
                        </table>
                      </div>
                      <div style="float: right;">
                        <button type="submit" class="btn btn-primary">Update</button>
                      </div>
                    </form>
                  </div>
                <?php } else { ?>
                  <label class="control-label">Add event results</label>
                  <div id="add_group_event_result">
                    <form class="form-horizontal" method="post" action="<?php echo base_url('groups_manage/group_event_result_add'); ?>">
                      <input type="hidden" name="csrf_token" value="<?php echo set_csrf_token(); ?>"/>
                      <input type="hidden" name="group_event_id" value="<?php echo $group_event_id; ?>"/>
                      <div>
                        <table class="table table-striped table-bordered">
                          <thead>
                            <tr>
                              <th width="5%">#</th>
                              <th width="50%">Group name</th>
                              <th width="10%">Score</th>
                              <th width="35%">Info</th>
                            </tr>
                          </thead>
                          <tbody>
                            <?php $count = 1; ?>
                            <?php foreach ($groups as $group) { ?>
                              <tr>
                                <td><?php echo $count; ?></td>
                                <td><?php echo $group['group_name']; ?></td>
                                <td><input name="group_score_<?php echo $group['group_id']; ?>" type="number" min="0" max="<?php echo (int) $group_event_data['group_event_max_score']; ?>" step="1" pattern="\d+" placeholder="0 - <?php echo (int) $group_event_data['group_event_max_score']; ?>"/></td>
                                <td><input name="group_info_<?php echo $group['group_id']; ?>" type="text"/></td>
                              </tr>
                              <?php $count++; ?>
                            <?php } ?>
                          </tbody>
                        </table>
                      </div>
                      <div style="float: right;">
                        <button type="submit" class="btn btn-primary">Save</button>
                      </div>
                    </form>
                  </div>
                <?php } ?>
              <?php } else { ?>
                <div class="alert alert-danger">No groups !</div>
              <?php } ?>
            <?php } else { ?>
              <div class="alert alert-info">Please select a group event !</div>
            <?php } ?>
          <?php } else { ?>
            <div class="alert alert-danger">No group events !</div>
          <?php } ?>
        </div>
      </div>
    </div>
  </div>
</div>